import java.util.*;

public class Demo {
    public static void main(String[] args) {
        List<Integer> nums = new ArrayList<>();
        nums.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return 0;
            }
        });
    }
}

// 注意类名必须为 Main, 不要有任何 package xxx 信息
class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String s1 = in.nextLine();
            String s2 = in.nextLine();
            if(s1.length()>s2.length()){
                String s = s1;
                s1 = s2;
                s2 = s;
            }
            int n = s1.length();
            int m = s2.length();
            int[][] dp = new int[n+1][m+1];
            int max = 0;int l=0,r=0;
            for(int i=1; i<=n; i++){
                for(int j=1; j<=m; j++){
                    if(s1.charAt(i-1)==s2.charAt(j-1)){
                        dp[i][j] = dp[i-1][j-1]+1;
                        if(max < dp[i][j]){
                            max = dp[i][j];
                            l = i-max;
                            r = i;
                        }
                    }
                }
            }
            if(max==0)
                System.out.println();
            else
                System.out.println(s1.substring(l,r));
        }
    }
}
class Solution {
    public int findKOr(int[] nums, int k) {
        int ans = -1;
        if(k == nums.length){
            for(int x : nums)
                ans &= x;
            return ans;
        }
        if(k == 1){
            ans = 0;
            for(int x : nums)
                ans |= x;
            return 0;
        }
        Map<Integer,Integer> map = new HashMap<>();
        Arrays.sort(nums);
        for(int x : nums){
            int i=0;
            while(x!=0){
                map.put(i,map.getOrDefault(map.get(i),0)+((x&1)==1?1:0));
                i++;
                x >>= 1;
            }
        }
        return 0;
    }
}
class Solution1 {
    public int hIndex(int[] citations) {
        int h = 0;
        Arrays.sort(citations);
        int n = citations.length;
        for(int i=0; i<n; i++){
            if(citations[i] >= n-i){
                h = Math.max(h,n-i);
            }
        }
        return h;
    }
}